from typing import List

from fastapi import APIRouter
from pydantic import BaseModel

from models import TaskVideo
from service.task_video_service import TaskVideoService

router = APIRouter()


# Pydantic Model for request body
class TaskVideoCreate(BaseModel):
    id: str
    type_name: str
    video_name: str
    image_url: str
    vidio_url: str
    vidio_path: str
    play_num: int
    release_time: str


@router.post("/task_videos/bulk_create")
def bulk_create_task_videos(videos_data: List[TaskVideoCreate]):
    service = TaskVideoService()
    videos = [TaskVideo(**video.dict()) for video in videos_data]
    return service.create_task_videos(videos)


@router.put("/task_videos/bulk_update")
def bulk_update_task_videos(videos_data: List[TaskVideoCreate]):
    service = TaskVideoService()
    videos = [TaskVideo(**video.dict()) for video in videos_data]
    return service.update_task_videos(videos)


@router.get("/task_videos/check_exists/{video_id}")
def check_task_video_exists(video_id: int):
    service = TaskVideoService()
    exists = service.check_task_video_exists(video_id)
    return {"exists": exists}


@router.get("/task_videos/all")
def get_all_task_videos():
    service = TaskVideoService()
    videos = service.get_all_task_videos()
    return videos


@router.get("/task_videos/paginated")
def get_task_videos_paginated(skip: int = 0, limit: int = 100):
    service = TaskVideoService()
    videos = service.get_task_videos_paginated(skip, limit)
    return videos


@router.delete("/task_videos/delete/{video_id}")
def delete_task_video(video_id: int):
    service = TaskVideoService()
    deleted = service.delete_task_video_by_id(video_id)
    return {"deleted": deleted}
